
public class Main {
    public static int[][] helix(int n){
        int[][] a=new int[n][n];
        int i = 0;
        int j = 0;
        int k = 1;
        for(int s=0;s<n/2;s++)
        {
            for (j = s; j < n-s-1; j++)
            {
                a[s][j] = k++;
            }
            for (i = s; i < n-s-1; i++)
            {
                a[i][j] = k++;
            }
            for ( ; j > s; j--)
            {
                a[i][j] = k++;
            }
            for (; i > s; i--)
            {
                a[i][j] = k++;
            }
        }
        if (n % 2 == 1)
            a[n/2][n/2] = k;
        return a;
    }
    public static void main(String[] args) {
        int[][] b=helix(5);
        int i=0;
        for (i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                System.out.printf("%2d ",b[i][j]);
            }
            System.out.println();
        }
    }
}